import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import { router } from "./router";
import "./public-path";
import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";
let app: any;

function render(props: any = {}) {
  const { container } = props;

  app = createApp(App);
  app.use(router);

  const containerElement = container ? container.querySelector("#app") : "#app";

  app.mount(containerElement || "#app");
}
// 独立运行
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
} else {
  renderWithQiankun({
    mount(props) {
      render(props);
    },
    bootstrap() {
      console.log("vue3 bootstrap");
    },
    update() {
      console.log("vue3 update");
    },
    unmount() {
      console.log("vue3 unmount");
      app?.unmount();
    },
  });
}
